package com.cskaoyan.utils;

import java.util.Random;

/**
 * 获取验证码
 * @author Fyy
 * @since 2023/01/02 12:05
 */

public class CodeUtil {
    public static String getVerificationCode(){
        String num = "0123456789";
        String code = "";
        for (int i = 0; i < 6; i++) {
            Random random = new Random();
            int index = random.nextInt(10);
            char[] chars = num.toCharArray();
            char number = chars[index];
            code += number;
        }
        return code;
    }

    public static String getCouponCode(){
        String num = "0123456789";
        char alphabet1 = 65;
        char alphabet2 = 97;
        for (int i = 0; i < 26; i++) {
            num += alphabet1;
            alphabet1++;
        }
        for (int i = 0; i < 26; i++) {
            num += alphabet2;
            alphabet2++;
        }
        String code = "";
        for (int i = 0; i < 8; i++) {
            Random random = new Random();
            int index = random.nextInt(62);
            char[] chars = num.toCharArray();
            char number = chars[index];
            code += number;
        }
        System.out.println(code);
        return code;
    }
}
